﻿using YK.Console.Business.DataDictItems;
using YK.Console.Business.DataDicts;
using YK.Console.Core.Consts;

namespace YK.Console;

/// <summary>
/// 数据字典服务
/// </summary>
[DynamicApi(Area = ConsoleAppConsts.ApiGroup),Order(110)]
public class DataDictService(ISender _sender):IDynamicApi
{
    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<Guid> CreateAsync(CreateDataDictRequest request, CancellationToken cancellationToken)
        => _sender.Send(request, cancellationToken);

    /// <summary>
    /// 创建子项
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<Guid> CreateItemAsync(CreateDataDictItemRequest request, CancellationToken cancellationToken)
        => _sender.Send(request, cancellationToken);

    /// <summary>
    /// 编辑
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<Guid> UpdateAsync(UpdateDataDictRequest request, CancellationToken cancellationToken)
        => _sender.Send(request,cancellationToken);

    /// <summary>
    /// 编辑子项
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<Guid> UpdateItemAsync(UpdateDataDictItemRequest request, CancellationToken cancellationToken)
        => _sender.Send(request,cancellationToken);

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="id"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<int> DeleteAsync([Required] Guid id, CancellationToken cancellationToken)
        => _sender.Send(new DeleteDataDictRequest(id), cancellationToken);

    /// <summary>
    /// 删除子项
    /// </summary>
    /// <param name="id"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<int> DeleteItemAsync([Required] Guid id, CancellationToken cancellationToken)
        => _sender.Send(new DeleteDataDictItemRequest(id), cancellationToken);

    /// <summary>
    /// 列表查询
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<List<DataDictOutput>> ListAsync(DataDictSearchRequest request, CancellationToken cancellationToken)
        => _sender.Send(request, cancellationToken);

    /// <summary>
    /// 子项列表查询
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<List<DataDictItemOutput>> ItemListAsync(DataDictItemSearchRequest request, CancellationToken cancellationToken)
        => _sender.Send(request,cancellationToken);

    /// <summary>
    /// 分页查询
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<PaginationResponse<DataDictOutput>> PageAsync(DataDictPageRequest request, CancellationToken cancellationToken)
        => _sender.Send(request, cancellationToken);

    /// <summary>
    /// 子项分页查询
    /// </summary>
    /// <param name="request"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task<PaginationResponse<DataDictItemOutput>> ItemPageAsync(DataDictItemPageRequest request,CancellationToken cancellationToken)
        =>_sender.Send(request,cancellationToken);
}
